import time

# 计时类
class Timer:
    def __init__(self):
        self._start_time = None
        self._elapsed_time = 0

    def start(self):
        """开始计时"""
        if self._start_time is not None:
            print("计时器已在运行，请先停止它以重新开始。")
        else:
            self._start_time = time.time()

    def stop(self):
        """停止计时并记录已用时间"""
        if self._start_time is None:
            print("计时器尚未启动。请先启动计时器。")
        else:
            self._elapsed_time += time.time() - self._start_time
            self._start_time = None

    def reset(self):
        """重置计时器"""
        self._start_time = None
        self._elapsed_time = 0

    def elapsed(self):
        """返回总运行时间，以分钟、秒和毫秒格式输出"""
        total_time = self._elapsed_time
        if self._start_time is not None:
            # 如果计时器在运行，计算到当前的总时间
            total_time += time.time() - self._start_time

        minutes = total_time / (60*60)
        seconds = total_time
        milliseconds = total_time * 1000

        print(f"Elapsed Time: {minutes:.4f} minutes")
        print(f"Elapsed Time: {seconds:.4f} seconds")
        print(f"Elapsed Time: {milliseconds:.4f} milliseconds")

    def __str__(self):
        return self.elapsed()
